{% extends "admin/base/index.html" %}
{% block title %}Post管理{% endblock %}
{% block style %}
    <link rel="stylesheet" href="{{ url_for("static",filename="admin/libs/zTree/v3/css/zTreeStyle/zTreeStyle.css") }}">
{% endblock %}
{% block navbar %}
    <nav class="breadcrumb" style="background-color:#fff;padding: 0 24px">
        首页
        <span class="c-gray en">/</span>
        POST管理
        <span class="c-gray en">/</span>
        POST列表
    </nav>
{% endblock %}
{% block main %}
    <div class="pos-a"
         style="width:150px;left:0;top:0; margin-top: 60px; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5">
        <ul id="ztree" class="ztree">
        </ul>
    </div>
    <div style="margin-left:150px;padding: 20px;">
        <div class="panel">
            <div class="panel-body" 发布>
                <div class="text-c"> 日期范围：
                    <input type="text" id="search-datetime-start" class="input-text datetimepicker-input"
                           style="width:120px;">
                    -
                    <input type="text" id="search-datetime-end" class="input-text datetimepicker-input"
                           style="width:120px;">
                    <input type="text" name="" id="" placeholder=" 产品名称" style="width:250px" class="input-text">
                    <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i>
                        搜产品
                    </button>
                </div>
            </div>
        </div>

        <div class="panel mt-20">
            <div class="panel-body" 发布>
                <div class="clearfix">
							<span class="f-l">
								<a class="btn btn-primary radius"
                                   onclick="full('添加POST文','{{ url_for('admin.admin_post_add') }}')"
                                   href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加POST文</a>
							</span>
                    <span class="f-r">共有数据：<strong>{{ count }}</strong> 条</span>
                </div>
                <div class="mt-20 clearfix">
                    <table class="table table-border table-bordered table-bg table-hover table-sort">
                        <thead>
                        <tr class="text-c">
                            <th width=6%>ID</th>
                            <th width=20%>POST文名称</th>
                            <th width=20%>关键词</th>
                            <th>描述</th>
                            <th width=8%>发布状态</th>
                            <th width=8%>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for item in data %}
                            <tr class="text-c va-m">
                                <td>{{ item.id }}</td>
                                <td class="text-l">
                                    <a style="text-decoration:none"
                                       onClick="product_show('{{ item.name }}','product-add.html','10001')"
                                       href="javascript:;">{{ item.name }}
                                    </a>
                                </td>
                                <td class="text-l">{{ item.keywords }}</td>
                                <td class="text-l">
                                    {{ item.description }}
                                </td>
                                <td class="td-status">
                                    <span class="label label-success radius">
                                        {% if item.status == 1 %}
                                            已发布
                                        {% else %}
                                            未发布
                                        {% endif %}
                                    </span>
                                </td>
                                <td class="td-manage text-l"><a class="btn btn-primary size-MINI"
                                                                onClick="full('编辑PO文','{{ url_for('admin.admin_post_edit',id=item.id) }}')"
                                                                href="javascript:;" title="编辑">
                                    <i class="Hui-iconfont">&#xe6df;</i></a>
                                    <a class="btn btn-secondary size-MINI"
                                       onClick="change_status('{{ url_for('admin.admin_post_start',id=item.id) }}')"
                                       href="javascript:;" title="发布">
                                        <i class="Hui-iconfont">&#xe603;</i></a>
                                    <a class="btn btn-warning size-MINI"
                                       onClick="change_status('{{ url_for('admin.admin_post_stop',id=item.id) }}')"
                                       href="javascript:;" title="删除">
                                        <i class="Hui-iconfont">&#xe6e2;</i></a></td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block javascript %}
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript"
            src="{{ url_for('static',filename="admin/libs/datatables/1.10.15/jquery.dataTables.min.js") }}"></script>
    <script type="text/javascript" src="{{ url_for('static',filename="admin/libs/laypage/1.2/laypage.js") }}"></script>
    <script type="text/javascript"
            src="{{ url_for('static',filename="admin/libs/zTree/v3/js/jquery.ztree.all-3.5.min.js") }}"></script>
    <script type="text/javascript" src="{{ url_for('static',filename="admin/business/js/main.js") }}"></script>
    <script>
        $(function () {
            runDatetimePicker();
            $("#menu-post dt").addClass("selected");
            $("#menu-post dd").css("display", "block");
            $("#menu-post .post-content").addClass("current");
        });

        function change_status(url) {
            $.ajax({
                type: "get",
                url: url,
                dataType: "json",
                success: function (result) {
                    if (result.status === true) {
                        layer.msg(result.message, {'icon': 1, 'time': 500}, function () {
                            window.location.replace(location.href)
                        })
                    } else {
                        layer.msg(result.message, {'icon': 5, 'time': 6000})
                    }
                }
            })
        };
        var setting = {
            view: {
                dblClickExpand: false,
                showLine: false,
                selectedMulti: false
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pid",
                    rootPId: ""
                }
            },
            callback: {
                beforeClick: function (treeId, treeNode) {
                    var zTree = $.fn.zTree.getZTreeObj("tree");
                    if (treeNode.isParent) {
                        zTree.expandNode(treeNode);
                        return false;
                    } else {
                        demoIframe.attr("src", treeNode.file + ".html");
                        return true;
                    }
                }
            }
        };
        var zNodes = {{ category|safe }};
        $(document).ready(function () {
            var t = $("#ztree");
            t = $.fn.zTree.init(t, setting, zNodes);
            demoIframe = $("#testIframe");
            var zTree = $.fn.zTree.getZTreeObj("tree");
            zTree.selectNode(zTree.getNodeByParam("id", '11'));
        });

    </script>
{% endblock %}